from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils import timezone
from auditlog.models import AuditlogHistoryField
from auditlog.registry import auditlog


class UserManager(models.Manager):
    def create_u(self, username, password, email):
        user = self.model()
        user.username = username
        user.password = password
        user.email = email
        return user


class User(AbstractUser):
    create_time = models.DateTimeField('注册时间', default=timezone.now)
    history = AuditlogHistoryField(pk_indexable=False)

    def __str__(self):
        return self.username + ': ' + self.email

    # objects = models.Manager()
    # MyObjects = UserManager()

    # class Meta:
    #     abstract = True      # 抽象类，不会创建数据库的表


# mapping_fields={'sku': 'Product No.', 'version': 'Product Revision'}
auditlog.register(User, exclude_fields=['password'])
